package com.ruoyi.web.controller.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.web.controller.user.request.ApiLoginRequest;

@RequestMapping("/api/user")
@RestController
public class ApiUserController {
	@Autowired
	TokenService tokenService;

	@PostMapping("/login")
	public AjaxResult login(ApiLoginRequest request) {
		if(!SecurityUtils.matchesPassword(request.getPassword(), "")) {
			return AjaxResult.error("用户名或密码不匹配");
		}
		LoginUser apiLoginUser = new LoginUser();
		String token = tokenService.createToken(apiLoginUser);
		apiLoginUser.setToken(token);
		return AjaxResult.success(apiLoginUser);
	}
}
